home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
public
/
Xprof
/
xmeasure
/
tsttxt.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
11KB
|
451 lines
/*==================================================================
* File : tsttxt.c
* Package: Xmeasure
*
* Author : Aloke Gupta.
*
* (C) Copyright 1992, Aloke Gupta.
* All rights granted to University of Illinois Board of Regents.
*==================================================================*/
#include "perf.h"
/* Shared variables */
static int i;
static Font font;
static XFontStruct *fontstruct;
static GC fontgc;
static int fontheight;
/* The following definition may be needed for DECWindows server */
/*
static char *FontName[] = {"times_roman10", "times_roman8", "times_roman12"};
*/
char *FontName[] = {
"6x13", "8x13", "9x15", NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
};
unsigned NUMFONTS = sizeof (FontName) / sizeof (char *);
#define FIRSTASCII ' '
#define LASTASCII 127
#define XPOS 20
/* ====================================================================== */
int OpenFont(xd, xp)
XD *xd;
XParams *xp;
{
for (i = 0; i < xp-> itns; i ++)
XLoadFont(xd->display, FontName[0]);
}
int i_OpenFont(xd, xp)
XD *xd;
XParams *xp;
{ }
int c_OpenFont(xd, xp)
XD *xd;
XParams *xp;
{ }
/* ====================================================================== */
int CloseFont(xd, xp)
XD *xd;
XParams *xp;
{
for (i = 0; i < xp-> itns; i ++)
XUnloadFont(xd->display, font);
}
int i_CloseFont(xd, xp)
XD *xd;
XParams *xp;
{
font = XLoadFont(xd->display, FontName[0]);
fontgc = XCreateGC(xd->display, xd->window, 0, 0);
XSetFont(xd->display, fontgc, font);
}
int c_CloseFont(xd, xp)
XD *xd;
XParams *xp;
{ XFreeGC(xd->display, fontgc); }
/* ====================================================================== */
static XFontStruct *font_struct;
static XFontStruct **font_struct_array;
int QueryFont(xd, xp)
XD *xd;
XParams *xp;
{
for (i = 0; i < xp-> itns; i ++)
font_struct_array[i] = XQueryFont(xd->display, font);
}
int i_QueryFont(xd, xp)
XD *xd;
XParams *xp;
{
font = XLoadFont(xd->display, FontName[0]);
font_struct = XQueryFont(xd->display, font);
font_struct_array=(XFontStruct **) malloc (xp->itns * sizeof (XFontStruct *));
}
int c_QueryFont(xd, xp)
XD *xd;
XParams *xp;
{
XFreeFont(xd->display, font_struct); /* Release the "FontName[0]" font */
for (i = 0; i < xp-> itns; i ++)
XFree(font_struct_array[i]);
free(font_struct_array);
}
/* ====================================================================== */
int QueryTextExtents(xd, xp)
XD *xd;
XParams *xp;
{
int direction, ascent, descent;
XCharStruct overall;
char *string = "test string for QueryTextExtents";
int nchars;
nchars = strlen(string);
for (i = 0; i < xp-> itns; i ++)
XQueryTextExtents(xd->display, font, string, nchars, &direction,
&ascent, &descent, &overall);
}
int i_QueryTextExtents(xd, xp)
XD *xd;
XParams *xp;
{
font = XLoadFont(xd->display, FontName[0]);
}
int c_QueryTextExtents(xd, xp)
XD *xd;
XParams *xp;
{ }
/* ====================================================================== */
static char ***list_fonts;
static int num_fonts;
static char * list_font_string = "*misc*";
int ListFonts(xd, xp)
XD *xd;
XParams *xp;
{
for (i = 0; i < xp-> itns; i ++)
list_fonts[i] = XListFonts(xd->display, list_font_string,
MAXINT, &num_fonts);
}
int i_ListFonts(xd, xp)
XD *xd;
XParams *xp;
{
list_fonts = (char ***) malloc(sizeof(char **) * xp->itns);
}
int c_ListFonts(xd, xp)
XD *xd;
XParams *xp;
{
for (i = 0; i < xp-> itns; i ++)
XFreeFontNames(list_fonts[i]);
free(list_fonts);
}
/* ====================================================================== */
int ListFontsWithInfo(xd, xp)
XD *xd;
XParams *xp;
{
for (i = 0; i < xp-> itns; i ++)
list_fonts[i] = XListFontsWithInfo(xd->display, list_font_string,
MAXINT, &num_fonts, &fontstruct);
}
int i_ListFontsWithInfo(xd, xp)
XD *xd;
XParams *xp;
{
list_fonts = (char ***) malloc(sizeof(char **) * xp->itns);
}
int c_ListFontsWithInfo(xd, xp)
XD *xd;
XParams *xp;
{
for (i = 0; i < xp-> itns; i ++)
XFreeFontNames(list_fonts[i]);
free(list_fonts);
}
/* ====================================================================== */
static char **font_path;
int SetFontPath(xd, xp)
XD *xd;
XParams *xp;
{
for (i = 0; i < xp-> itns; i ++)
XSetFontPath(xd->display, font_path, num_fonts);
}
int i_SetFontPath(xd, xp)
XD *xd;
XParams *xp;
{
font_path = XGetFontPath(xd->display, &num_fonts);
}
int c_SetFontPath(xd, xp)
XD *xd;
XParams *xp;
{
XFree(font_path);
}
/* ====================================================================== */
int GetFontPath(xd, xp)
XD *xd;
XParams *xp;
{
for (i = 0; i < xp-> itns; i ++)
list_fonts[i] = XGetFontPath(xd->display, &num_fonts);
}
int i_GetFontPath(xd, xp)
XD *xd;
XParams *xp;
{
list_fonts = (char ***) malloc(sizeof(char **) * xp->itns);
}
int c_GetFontPath(xd, xp)
XD *xd;
XParams *xp;
{
for (i = 0; i < xp-> itns; i ++)
XFree(list_fonts[i]);
free(list_fonts);
}
/* ====================================================================== */
/* PolyText8: Sizepair => (string_length, font_index) */
static char **buffer;
int PolyText8(xd, xp)
XD *xd;
XParams *xp;
{
int ypos = XPOS;
for (i = 0; i < xp->itns; i++) {
XDrawString(xd->display, xd->window, fontgc, XPOS, ypos,
buffer[i], (int) xp->size);
ypos += fontheight;
if (ypos > (DISPHEIGHT - fontheight))
ypos = XPOS;
}
}
int i_PolyText8(xd, xp)
XD *xd;
XParams *xp;
{
XGCValues gcval;
int j, fontindex;
short aflag=0;
char c;
xp->size = xp->sizepair->s1;
xp->numobjs = xp->sizepair->s1;
fontindex = xp->sizepair->s2;
if (fontindex < 0) fontindex = 0;
else if (fontindex > NUMFONTS) fontindex = NUMFONTS;
/* Load the font */
fontstruct = XLoadQueryFont(xd->display, FontName[fontindex]);
if (fontstruct == NULL) {
printf("Error: could not load font '%s'\n", FontName[fontindex]);
xp->itns = 0;
}
fontheight=fontstruct->max_bounds.ascent + fontstruct->max_bounds.descent+1;
/* Create a graphics context for the text requests */
fontgc = XCreateGC(xd->display, xd->window, 0, 0);
gcval.font = fontstruct->fid;
XChangeGC(xd->display, fontgc, GCFont, &gcval);
XSetBackground(xd->display, fontgc, xd->background);
XSetForeground(xd->display, fontgc, xd->foreground);
/* Setup strings to be drawn by the PolyText request */
buffer = (char **) malloc(xp->itns * sizeof(char *));
for (i = 0; i < xp->itns; i++) {
buffer[i] = (char *) malloc(xp->size * sizeof (char));
c = (char) (i + FIRSTASCII);
for (j = 0; j < xp->size; j++) {
buffer[i][j] = c;
if (c == LASTASCII) c = (char) FIRSTASCII;
else c++;
}
}
while (XTextWidth(fontstruct, buffer[0], (int) xp->size) > DISPWIDTH) {
aflag = 1;
xp->size --;
}
if (aflag) fprintf(stderr, "# Warning: Adjusted string length to %d\n", xp->size);
}
int c_PolyText8(xd, xp)
XD *xd;
XParams *xp;
{
XFreeGC(xd->display, fontgc);
for (i = 0; i < xp->itns; i++)
free(buffer[i]);
free(buffer);
}
/* ====================================================================== */
/* PolyText16: Sizepair => (string_length, font_index) */
XChar2b **buffer16;
int PolyText16(xd, xp)
XD *xd;
XParams *xp;
{
int ypos = XPOS;
for (i = 0; i < xp->itns; i++) {
XDrawString16(xd->display, xd->window, fontgc, XPOS, ypos,
buffer16[i], xp->size);
ypos += fontheight;
if (ypos > (DISPHEIGHT - fontheight))
ypos = XPOS;
}
}
int i_PolyText16(xd, xp)
XD *xd;
XParams *xp;
{
XGCValues gcval;
int j, fontindex;
short aflag=0;
char c;
xp->size = xp->sizepair->s1;
xp->numobjs = xp->sizepair->s1;
fontindex = xp->sizepair->s2;
if (fontindex < 0) fontindex = 0;
else if (fontindex > NUMFONTS) fontindex = NUMFONTS;
/* Load the font */
fontstruct = XLoadQueryFont(xd->display, FontName[fontindex]);
if (fontstruct == NULL) {
printf("Error: could not load font '%s'\n", FontName[fontindex]);
xp->itns = 0;
}
fontheight=fontstruct->max_bounds.ascent + fontstruct->max_bounds.descent+1;
/* Create a graphics context for the text requests */
fontgc = XCreateGC(xd->display, xd->window, 0, 0);
gcval.font = fontstruct->fid;
XChangeGC(xd->display, fontgc, GCFont, &gcval);
XSetBackground(xd->display, fontgc, xd->background);
XSetForeground(xd->display, fontgc, xd->foreground);
/* Setup strings to be drawn by the PolyText request */
buffer16 = (XChar2b **) malloc(xp->itns * sizeof(XChar2b *));
for (i = 0; i < xp->itns; i++) {
buffer16[i] = (XChar2b *) malloc(xp->size * sizeof (XChar2b));
c = (char) (i + FIRSTASCII);
for (j = 0; j < xp->size; j++) {
buffer16[i][j].byte1 = (unsigned char) c;
buffer16[i][j].byte1 = (unsigned char) (LASTASCII - FIRSTASCII + c);
if (c == LASTASCII) c = (char) FIRSTASCII;
else c++;
}
}
while (XTextWidth16(fontstruct, buffer16[0], (int) xp->size) > DISPWIDTH) {
aflag = 1;
xp->size --;
}
if (aflag) fprintf(stderr, "# Warning: Adjusted string length to %d\n", (int) xp->size);
}
int c_PolyText16(xd, xp)
XD *xd;
XParams *xp;
{
XFreeGC(xd->display, fontgc);
for (i = 0; i < xp->itns; i++)
free(buffer16[i]);
free(buffer16);
}
/* ====================================================================== */
/* ImageText8: Sizepair => (string_length, font_index) */
int ImageText8(xd, xp)
XD *xd;
XParams *xp;
{ int ypos = XPOS;
for (i = 0; i < xp->itns; i++) {
XDrawImageString(xd->display, xd->window, fontgc, XPOS, ypos,
buffer[i], (int) xp->size);
ypos += fontheight;
if (ypos > (DISPHEIGHT - fontheight))
ypos = XPOS;
}
}
int i_ImageText8(xd, xp)
XD *xd;
XParams *xp;
{ i_PolyText8(xd, xp); }
int c_ImageText8(xd, xp)
XD *xd;
XParams *xp;
{ c_PolyText8(xd, xp); }
/* ====================================================================== */
/* ImageText8: Sizepair => (string_length, font_index) */
int ImageText16(xd, xp)
XD *xd;
XParams *xp;
{ int ypos = XPOS;
for (i = 0; i < xp->itns; i++) {
XDrawImageString16(xd->display, xd->window, fontgc, XPOS, ypos,
buffer16[i], (int) xp->size);
ypos += fontheight;
if (ypos > (DISPHEIGHT - fontheight))
ypos = XPOS;
}
}
int i_ImageText16(xd, xp)
XD *xd;
XParams *xp;
{ i_PolyText16(xd, xp); }
int c_ImageText16(xd, xp)
XD *xd;
XParams *xp;
{ c_PolyText16(xd, xp); }